/**
 * Copyright (c) 2013 onionframework.org
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 */
package org.onionframework.code.service;

import java.io.Serializable;

import javax.annotation.PostConstruct;

import org.onionframework.code.model.CodeType;
import org.onionframework.persistence.dao.GenericDao;
import org.onionframework.persistence.service.GenericServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 * @author allan
 *
 */
@Service("code.codeTypeService")
public class CodeTypeService extends GenericServiceImpl<CodeType> {

	@Autowired  @Qualifier("code.codeTypeDao")
	private GenericDao<CodeType> codeTypeDao;
	
	@PostConstruct
	public void init(){
		super.setDao(this.codeTypeDao);
	}
	
	@Override
	@CacheEvict(value="onion.code.codeType",key="#codeType.name")
	public void save(CodeType codeType){
		super.save(codeType);
	}

	/**
	 * 获取代码类型
	 * @param name 代码类型名称
	 */
	@Cacheable(value="onion.code.codeType")
	public CodeType getCodeType(String name) {
		return this.findUnique("name", name);
	}
	
	@Override
	@CacheEvict(value="onion.code.codeType",key="#codeType.name")
	public void remove(CodeType codeType){
		super.remove(codeType);
	}
	
	@Override
	public void removeById(Serializable id){
		throw new UnsupportedOperationException("不支持此操作");
	}
}
